package com.groupseven.happycampus.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.groupseven.happycampus.common.pojo.BicycleSupplier;
import com.groupseven.happycampus.common.vo.BicycleSupplierBrandPieVo;
import com.groupseven.happycampus.common.vo.BicycleSupplierNameBarVo;
import com.groupseven.happycampus.common.vo.LayuiPageVo;
import com.groupseven.happycampus.mapper.BicycleSupplierMapper;
import com.groupseven.happycampus.service.BicycleSupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("bicycleSupplierService")
public class BicycleSupplierServiceImpl implements BicycleSupplierService {

    @Autowired
    private BicycleSupplierMapper bicycleSupplierMapper;

    @Override
    public LayuiPageVo<BicycleSupplier> bicycleSupplierList(Map<String, Object> params) {
        int page = Integer.parseInt(params.get("page") + "");
        int limit = Integer.parseInt(params.get("limit") + "");
        PageHelper.startPage(page,limit);
        List<BicycleSupplier> bicycleSuppliers = bicycleSupplierMapper.bicycleSupplierMapper(params);

        PageInfo<BicycleSupplier> bicycleSupplierPageInfo = new PageInfo<>(bicycleSuppliers);

        LayuiPageVo<BicycleSupplier> bicycleSupplierLayuiPageVo = new LayuiPageVo<>();

        bicycleSupplierLayuiPageVo.setCode(0);
        bicycleSupplierLayuiPageVo.setMsg("分页数据");
        bicycleSupplierLayuiPageVo.setCount(bicycleSupplierPageInfo.getTotal());
        bicycleSupplierLayuiPageVo.setData(bicycleSupplierPageInfo.getList());

        return bicycleSupplierLayuiPageVo;

    }

    @Override
    public int bicycleSupplierAdd(BicycleSupplier bicycleSupplier) {
        return bicycleSupplierMapper.bicycleSupplierAdd(bicycleSupplier);
    }

    @Override
    public int bicycleSupplierUpdate(BicycleSupplier bicycleSupplier) {
        return bicycleSupplierMapper.bicycleSupplierUpdate(bicycleSupplier);
    }

    @Override
    public int bicycleSupplierDelete(Integer id) {
        return bicycleSupplierMapper.bicycleSupplierDelete(id);
    }

    @Override
    public List<BicycleSupplierNameBarVo> echartNameBar() {
        return bicycleSupplierMapper.echartNameBar();
    }

    @Override
    public List<BicycleSupplierBrandPieVo> echartsBrandPie() {
        return bicycleSupplierMapper.echartsBrandPie();
    }

    @Override
    public int deleteSupplierByIds(String ids) {
        String[] arrId = ids.split(",");
        return bicycleSupplierMapper.deleteSupplierByIds(arrId);
    }
}
